<?php /*a:3:{s:65:"D:\PhpStorm\PhpStormProject\short_link\view\admin\link\index.html";i:1757168387;s:68:"D:\PhpStorm\PhpStormProject\short_link\view\admin\common\header.html";i:1753878054;s:68:"D:\PhpStorm\PhpStormProject\short_link\view\admin\common\footer.html";i:1753878054;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/static/admin/css/reset.css"/>
    <link rel="stylesheet" href="/static/admin/css/other/console1.css"/>
    <link rel="stylesheet" href="/static/component/layui/inputTag.css">
    <!-- 主 题 更 换 -->
    <style id="pearadmin-bg-color"></style>
</head>
<script src="/static/component/layui/layui.js"></script>
<script src="/static/component/pear/pear.js"></script>
<script src="/static/admin/js/common.js"></script>
<script src="/static/component/layui/iconPicker.js"></script>
<body class="pear-container">
<div class="layui-row layui-col-space10">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form top-search-from" id="layui-form" action="">
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">链接code</label>
                        <div class="layui-input-block">
                            <input type="text" name="link_code" placeholder="请输入链接code" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">链接地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="link_url" placeholder="请输入链接地址" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>重置
                        </button>
                    </div>
                    <div class="toggle-btn">
                        <a class="layui-hide">展开<i class="layui-icon layui-icon-down"></i></a>
                        <a class="layui-hide">收起<i class="layui-icon layui-icon-up"></i></a>
                    </div>
                </form>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="dict-table" lay-filter="dict-table"></table>
            </div>
        </div>
    </div>
</div>

</body>
<script type="text/html" id="dict-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
</script>

<script type="text/html" id="dict-bar">
    <button class="pear-btn pear-btn-primary pear-btn-xs" lay-event="edit">
        <i class="layui-icon">编辑</i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-xs" lay-event="remove">
        <i class="layui-icon">删除</i>
    </button>
</script>


<script>
    layui.use(['table', 'form', 'jquery', 'common', 'dropdown'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        let dropdown = layui.dropdown;

        let MODULE_PATH = "<?php echo htmlentities(app('request')->root()); ?>/Link/";

        table.render({
            elem: '#dict-table',
            url: MODULE_PATH + 'index',
            cols: [
                [
                    {title: '链接ID', field: 'link_id', align: 'center', width: 80},
                    {title: '链接code', field: 'link_code', align: 'center'},
                    {title: '长链接地址', field: 'link_url', align: 'center'},
                    {title: '过期时间', field: 'expire_time', align: 'center'},
                    {title: '创建时间', field: 'create_time', align: 'center'},
                    {title: '操作', toolbar: '#dict-bar', fixed: 'right', align: 'center', width: 135}
                ]
            ],
            cellMinWidth: 100,
            skin: 'grid',
            even: 'true',
            size: 'lg',
            page: true,
            toolbar: '#dict-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });

        form.on('submit(query)', function (data) {
            table.reload('dict-table', {
                where: data.field,
                page: {curr: 1}
            })
            return false;
        });

        table.on('tool(dict-table)', function (obj) {
            if (obj.event === 'edit') {
                window.edit(obj.data['link_id']);
            } else if (obj.event === 'remove') {
                window.remove(obj);
            }
        });
        table.on('toolbar(dict-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'export') {
                window.export();
            }
        });

        window.add = function () {
            layer.open({
                type: 2,
                maxmin: true,
                title: '添加链接',
                shade: 0.1,
                area: common.screenSmall(),
                content: MODULE_PATH + 'add'
            });
        }

        window.edit = function (id) {
            layer.open({
                type: 2,
                maxmin: true,
                title: '编辑链接',
                shade: 0.1,
                area: common.screenSmall(),
                content: MODULE_PATH + 'edit/id/' + id
            });
        }

        window.remove = function (obj) {
            layer.confirm('是否要删除该数据？', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + 'remove',
                    data: {id: obj.data['link_id']},
                    dataType: 'json',
                    type: 'POST',
                    success: function (res) {
                        layer.close(loading);
                        if (res.code == 200) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

        window.refresh = function () {
            table.reload('dict-table');
        }
    })
</script>
</html>
